/******************************************************************************
 * Filename : uc_tpool.h
 * Copyright: 
 * Created  : 2011-1-6 by franco.yin
 * Description -
 * 
 ******************************************************************************/

#ifndef _UC_TPOOL_H
#define _UC_TPOOL_H

#ifdef __cplusplus
extern "C" {
#endif

#include "uc_public.h"
#include "uc_thread.h"
#include "uc_func.h"

#define uctp_err(...)  		uc_err(__VA_ARGS__)
#define uctp_info(...)  		uc_info(__VA_ARGS__)
#define uctp_debug(...)  		

#define UCTP_MANAGE_INTERVAL 10
#define UCTP_STACK_SIZE 524288	/* 512K */

typedef void *(*uctp_job)(void *p1);

typedef struct uctp_thread{
	uclock_t		thread_lock;
	ucthread_cond_s		thread_cond;	
	pthread_t			thread_id;
	int					is_busy;
	uctp_job			pJob;
	void				*pParam;
}uctp_thread_s;

typedef struct uctp_main{
	ucthread_attr_s th_attr;
	uclock_t tp_lock;
	uctp_thread_s *thread_pool;
	int thread_count;
	int stacksize;
}uctp_main_s;

#define uctp_gettid()  (syscall(SYS_gettid))

extern void *uctp_creat(int thread_count, int stack_size);
extern int uctp_init(void *pThreadPool);
extern void uctp_close(void *pThreadPool);
extern void uctp_do_job(void *pThreadPool, uctp_job pJob, void *pParam, int only_pool);

#ifdef __cplusplus
}
#endif

#endif

